747B - Mammoth's Genome Decoding - CodeForces Solution


implementation strings *900

Please click on ads to support us..

Python Code:

import sys

n = int(input())
strk = input()
new_strk = ''
amn, ost = divmod (n, 4)

amn_A = strk.count('A')
amn_C = strk.count('C')
amn_G = strk.count('G')
amn_T = strk.count('T')

if ost != 0 or amn_A > amn or amn_C > amn or amn_G > amn or amn_T > amn:
    print ('===')
    sys.exit()
    
need_A = amn - amn_A
need_C = amn - amn_C
need_G = amn - amn_G
need_T = amn - amn_T

for j in strk:
    if j != '?':
        new_strk += j
    else:
        if need_A != 0:
            new_strk += 'A'
            need_A -= 1
        elif need_C != 0:
            new_strk += 'C'
            need_C -= 1
        elif need_G != 0:
            new_strk += 'G'
            need_G -= 1
        else:
            new_strk += 'T'

print (new_strk)    

C++ Code:

#include<bits/stdc++.h>
#include<iostream>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define yes cout<<"YES"<<"\n";
#define no cout<<"NO"<<"\n";
#define counterr cout<<counter<<"\n";counter=0;
#define asort sort(arr,arr+n);
#define dsort sort(arr,arr+n,greater<int>());
#define maxind  cout<< max_element(arr, arr + n) - arr<<endl;
#define pb(data) push_back(data);
#define eraseall(v,data) v.erase(remove(v.begin(),v.end(),data),v.end());
const int mod = 1e9+7;
using namespace std;
long long t,n,m,mn=LONG_MAX,mx=LONG_MIN,counter=0,c,q,x,y,z,d,sum=0,a,b,k,counter2=0;
string s1,s2,s3,s4,s,ss;
char ch;
bool sortbysec(const pair<string,long long> &a,
              const pair<string,long long> &b)
{
    if(a.second!=b.second)
    return (a.second > b.second);
    return a.first<b.first;
}
bool prime(long long n){
    if (n<2){
        return false;
    }
for ( int i=2 ; i*i<=n ; i++){
    if (n%i==0)
        return false;
}
return true;
}
int main()
{
    fast
    map<char,int>mp;
cin>>n>>s;
m=n/4;
for ( int i=0 ; i<s.size() ; i++){
    mp[s[i]]++;
}
if ( n%4!=0 || mp['A']>m || mp['G']>m || mp['C']>m || mp['T']>m){
    cout<<"===";
} else {
for ( int i=0 ; i<s.size() ; i++){
    if (s[i]=='?'){
        if (mp['A']!=m){
            s[i]='A';
            mp['A']++;
        } else if (mp['T']!=m){
        s[i]='T';
        mp['T']++;
        } else if (mp['C']!=m){
        s[i]='C';
        mp['C']++;
        } else {
        s[i]='G';

        }
    }
}
cout<<s;
}

}


Comments

Submit
0 Comments
More Questions

1006A - Adjacent Replacements
1195C - Basketball Exercise
1206A - Choose Two Numbers
1438B - Valerii Against Everyone
822A - I'm bored with life
9A - Die Roll
1430B - Barrels
279B - Books
1374B - Multiply by 2 divide by 6
1093B - Letters Rearranging
1213C - Book Reading
1468C - Berpizza
1546B - AquaMoon and Stolen String
1353C - Board Moves
902A - Visiting a Friend
299B - Ksusha the Squirrel
1647D - Madoka and the Best School in Russia
1208A - XORinacci
1539B - Love Song
22B - Bargaining Table
1490B - Balanced Remainders
264A - Escape from Stones
1506A - Strange Table
456A - Laptops
855B - Marvolo Gaunt's Ring
1454A - Special Permutation
1359A - Berland Poker
459A - Pashmak and Garden
1327B - Princesses and Princes
1450F - The Struggling Contestant